package library.and.xps.com.step;

import android.app.Application;
import android.os.Environment;

import com.baidu.mapapi.SDKInitializer;
//import com.facebook.stetho.Stetho;
import com.facebook.stetho.Stetho;
import com.jude.utils.JUtils;
import com.squareup.leakcanary.LeakCanary;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;
//import com.uphyca.stetho_realm.RealmInspectorModulesProvider;

import java.io.File;

import cn.jpush.android.api.JPushInterface;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import library.and.xps.com.step.util.LocationUtil;

public class App extends Application {
    private static App INSTANCE;

    /* 文件缓存的目录 */
    public String mAppDir;
    public String mPicturesDir;
    public String mFilesDir;

    @Override
    public void onCreate() {
        super.onCreate();
        INSTANCE = this;

        JUtils.initialize(this);
        JUtils.setDebug(true,"debug");

        Realm.init(this);
        //RealmConfiguration config = new RealmConfiguration.Builder().schemaVersion(0).migration(new MyMigration()).build();
        RealmConfiguration config = new RealmConfiguration.Builder().build();
        Realm.setDefaultConfiguration(config);

        // 极光初始化 JPush
        JPushInterface.init(this);
        JPushInterface.setDebugMode(false); // 设置开启日志

        SDKInitializer.initialize(this);

        Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                        .build());

        JUtils.getSharedPreference().edit().putString(SPConstant.USER_HEIGHT,"170cm").apply();
        JUtils.getSharedPreference().edit().putString(SPConstant.USER_STEP_PLAN,"7000").apply();
        JUtils.getSharedPreference().edit().putString(SPConstant.USER_EMAIL,"790928421@qq.com").apply();

        if (LeakCanary.isInAnalyzerProcess(this)) {
            // This process is dedicated to LeakCanary for heap analysis.
            // You should not init your app in this process.
            return;
        }
        LeakCanary.install(this);

        LocationUtil.InitLocation();
    }

    public static App getInstance() {
        return INSTANCE;
    }

    private void initAppDir() {
        File file = getExternalFilesDir(null);
        if (!file.exists()) {
            file.mkdirs();
        }

        mAppDir = file.getAbsolutePath();

        file = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        if (!file.exists()) {
            file.mkdirs();
        }

        mPicturesDir = file.getAbsolutePath();

        file = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
        if (!file.exists()) {
            file.mkdirs();
        }

        mFilesDir = file.getAbsolutePath();
    }

}
